home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / mscheap2 / dbugdemo.c < prev    next >
C/C++ Source or Header  |  1990-03-13  |  1KB  |  48 lines

  1. //
  2. //     Copyright (c) 1990 by Optimal Software, All Rights Reserved
  3. //
  4.  
  5. //
  6. //    A demonstration of the debug functions in the replacement heap manager
  7. //
  8. //    We allocate a bunch of blocks and then trigger a diagnostic dump by
  9. //    overwriting the end of a block
  10. //
  11.  
  12. #if !defined( _HEAPDEBUG ) && !defined( _HEAPTRACE )
  13.    #define _HEAPDEBUG stdout  /* in place of a compiler switch */
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18.  
  19. #include <heap.h>
  20.  
  21. void main()
  22. {
  23. char far *ptr;
  24.  
  25. int index;
  26.  
  27. _heappad = 8;                       /* set the safety margin */
  28.  
  29. for ( index=1 ; index<=10 ; index++ )
  30.    {
  31.    ptr = _fmalloc( 100 );           /* these will share the same debug info */
  32.  
  33.    _fheapwatch( ptr, 1 );           /* declare them as read-only */
  34.    }
  35.  
  36. srand(12345);
  37.  
  38. for ( index=1 ; index<=10 ; index++ )
  39.  
  40.    _fmalloc ( rand() % 1000 );      /* these will be unique */
  41.  
  42. ptr = _fmalloc(8);                  /* so will this */
  43.  
  44. ptr[-1] = 0;      /* overwrite the safety margin */
  45.  
  46. _fmalloc( 8 );    /* this should detect the error */
  47. }
  48.